//
//  EnterDaveIDViewController.m
//  Project6
//
//  Created by ToanDK on 11/14/12.
//  Copyright (c) 2012 DungNP. All rights reserved.
//

#import "EnterDaveIDViewController.h"
#import "NewReportViewController.h"

@interface EnterDaveIDViewController ()

@end

@implementation EnterDaveIDViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"greyBackground"]];
    // Do any additional setup after loading the view from its nib.
    UIImage* buttonImage =[[UIImage imageNamed:@"greenButton"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
    UIImage* buttonImageON =[[UIImage imageNamed:@"greenButtonOn"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
    
    [btnSubmit setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [btnSubmit setBackgroundImage:buttonImageON forState:UIControlStateHighlighted];
    [btnSubmit setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnSubmit setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    // Set key board type for 2 text fields
    [txtWTGDaveID setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
    [txtWindFarmTurbineID setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)btnSubmit_Click:(id)sender
{
    NSLog(@"btnSubmit_Click");
    // Go to new report screen
    NewReportViewController *newReport = [[NewReportViewController alloc] initWithNibName:@"NewReportViewController" bundle:nil];
    newReport.FARM_ID = txtWTGDaveID.text;
    newReport.WTG_ID = txtWindFarmTurbineID.text;
    // Check user input WTG Dave ID and WindFarmTurbine ID
    if( [newReport.FARM_ID isEqualToString:@""] || [newReport.WTG_ID isEqualToString:@""] )
    {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Manual Enter Dave ID" message:@"Please input values for both 2 fields" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else
    {
          [self.navigationController pushViewController:newReport animated:YES];
    }
    
}
// implement textfile delegate to hide the keyboard on textfield
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    if(textField == txtWTGDaveID)
    {
        [txtWTGDaveID setReturnKeyType:UIReturnKeyNext];
        [txtWindFarmTurbineID becomeFirstResponder];
    }
    else
        [txtWTGDaveID setReturnKeyType:UIReturnKeyDone];
    
    
    return YES;
}

@end
